// 动态规划
const CASHES: [u32; 8] = [1, 2, 5, 10, 20, 30, 50, 100];

pub fn dp_rec_mc(amount: u32) -> u32 {
    if amount == 0 {
        return 0;
    }
    
    let mut min_cashes = vec![u32::MAX; amount as usize + 1];
    min_cashes[0] = 0;
    
    // 对每个金额从1到amount进行计算
    for current_amount in 1..=amount as usize {
        // 尝试每种面额的纸币
        for &cash in CASHES.iter() {
            if cash as usize <= current_amount {
                // 如果之前的解存在（不是u32::MAX）
                if min_cashes[current_amount - cash as usize] != u32::MAX {
                    // 更新最小找零数
                    min_cashes[current_amount] = min_cashes[current_amount]
                        .min(min_cashes[current_amount - cash as usize] + 1);
                }
            }
        }
    }
    
    // 如果无法找零，返回0，否则返回最小找零数
    if min_cashes[amount as usize] == u32::MAX {
        0
    } else {
        min_cashes[amount as usize]
    }
}


